#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include "iostream"

int main(int argc, char **argv) {
    // 初始化ROS节点
    ros::init(argc, argv, "cre_move_forward_node");
    ros::NodeHandle nh;

    // 创建/cmd_vel话题的发布者
    ros::Publisher cmd_vel_pub = nh.advertise<geometry_msgs::Twist>("cmd_vel", 10);

    // 设置发布速度消息的频率
    ros::Rate rate(10);

    // 创建Twist消息并初始化速度
    geometry_msgs::Twist twist;
    twist.linear.x = 0.1;

    // 发布速度消息，持续1秒
    ros::Time start_time = ros::Time::now();
    while (ros::Time::now() - start_time < ros::Duration(5.0)) {
        cmd_vel_pub.publish(twist);
        std::cout << "move . " << std::endl;
        rate.sleep();
    }

    // 停止机器人运动
    twist.linear.x = 0.0;
    cmd_vel_pub.publish(twist);

    return 0;
}
